import {computed, reactive} from "vue";
import {useStore, mapState} from "vuex";

export function useState(moduleName: string, mapper: string[]): Object {
  const store = useStore()
  //  获取到对应对象的functions
  const storeStateFns = mapState(moduleName, mapper)
  //对数据进行转换
  const storeState = {}
  Object.keys(storeStateFns).forEach(fnKey => {
    const fn = storeStateFns[fnKey].bind({$store: store})
    // @ts-ignore
    storeState[fnKey] = computed(fn)
  })
  return storeState
}
